package com.ice.body.hardware.controller;
import com.ice.body.hardware.model.DeviceAir;
import com.ice.body.hardware.service.DeviceAirService;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import com.ice.base.controller.BaseController;
import org.slf4j.Logger;
import com.github.pagehelper.PageHelper;
import org.springframework.util.StringUtils;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import com.ice.base.result.ResponseResult;
import com.ice.base.result.AjaxResult;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
/**
 * Created with GuoYanBin.
 * Description:
 * Date: 2022-11-11
 * Time: 02:33
 */
@RestController
@ApiIgnore(value = "tovc空气质量")
public class DeviceAirController extends BaseController{
    private Logger logger = LoggerFactory.getLogger(getClass());
    //---------------------------tovc空气质量-----------------------start
    @Resource
    private DeviceAirService deviceAirService;
    
    @ApiOperation(value = "tovc空气质量-新增")
    @PostMapping("/api/DeviceAir/insert")
    public AjaxResult<DeviceAir> insert_DeviceAir(DeviceAir model) {
        AjaxResult r = AjaxResult.success();
        try{
            Integer count  = deviceAirService.insert(model);
        }catch (Exception e){
            e.printStackTrace();
            r = AjaxResult.error(); 
        }
        return r;
    }

    @ApiOperation(value = "tovc空气质量-删除")
    @PostMapping("/api/DeviceAir/deleteById")
    public AjaxResult<DeviceAir>  deleteById_DeviceAir(@RequestParam("id") String id) {
        AjaxResult r = AjaxResult.success();
        try{
            Integer count =deviceAirService.delete(id);
        }catch (Exception e){
            e.printStackTrace();
            r = AjaxResult.error();  
        }
        return r;
    }

    @ApiOperation(value = "tovc空气质量-更新")
    @PostMapping("/api/DeviceAir/updateById")
    public AjaxResult<DeviceAir> update_DeviceAir(DeviceAir model) {
        try{
            Integer count =deviceAirService.update(model);
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.error();      
        }
        return AjaxResult.success();
    }

    @ApiOperation(value = "tovc空气质量-查询一个")
    @PostMapping("/api/DeviceAir/selectById")
    public AjaxResult<DeviceAir> selectById_DeviceAir(@RequestParam("id") String id) {
        AjaxResult r = ResponseResult.success();
        try{
           DeviceAir model = deviceAirService.selectById(id);
           r.setData(model);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "tovc空气质量-查询多个")
    @PostMapping("/api/DeviceAir/selectAll")
    public AjaxResult<DeviceAir> selectList_DeviceAir(DeviceAir model) {
        AjaxResult r = AjaxResult.success();
        try{
           List<DeviceAir> list = deviceAirService.selectListByModel(model);
           r.setData(list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }

    @ApiOperation(value = "tovc空气质量-查询分页")
    @PostMapping("/api/DeviceAir/selectListByPageHelper")
    public AjaxResult<DeviceAir> selectListByPageHelper_DeviceAir(@RequestParam(name = "pageSize") Integer pageSize,
                                                         @RequestParam(name = "pageNum") Integer pageNum,
                                                         DeviceAir model){ 
        AjaxResult r = AjaxResult.success();
        ArrayList list;
        try{
           PageHelper.startPage(pageNum, pageSize);
             list = deviceAirService.selectListByModel(model);
           getReturnResultByPage(r,list);
        }catch (Exception e){
            e.printStackTrace();
            r = ResponseResult.error();   
        }
        return r;
    }
    //---------------------------tovc空气质量-----------------------end
}
